﻿///<reference path="microsoftajax.debug.js" />


// System
(function() {

		var amp = function(selector) {
			///<returns type="amp.UI.Dom"></returns>
			return (selector.get) ? selector : new amp.UI.Dom(selector);
		}

		window.amp = amp;

		amp.UI = { __type: "amp.UI", __namespace: true };
		amp.Threading = { __type: "amp.Threading", __namespace: true };
		amp.Cache = { window: {}, __type: "amp.Cache", __namespace: true };

		amp.setValue = function(path, value) {
			var parts = path.split("."), obj = window, part = null;
			for (var i = 0; i < parts.length; i++) {
				part = parts[i];
				if (obj[part] === undefined)
					obj[part] = {};

				if (i == (parts.length - 1))
					obj[part] = value;
				else
					obj = obj[part];
			}

			return obj[part];
		}

		amp.log = function(message, level, category) {
			var el = window._log ? window._log : document.getElementById("log"),
		level = level ? level : "debug",
		category = category ? category : "default";
			if (el)
				el.appendChild(document.createElement("<div class='" + level + "'><span class='category'>" + category + "</span><span class='message'>" + message + "</span></div>"));
			else
				alert(message);
		}




		window.amp.extend = function(destination, target) {
			for (var property in target)
				destination[property] = target[property];
			return destination;
		};




		amp.empty = function() { }


		amp.extend(amp, {
			isString: function(value) { return typeof (value) == "string"; },

			isFunction: function(value) { return typeof (value) === "function"; },

			isArray: function(value) { return (value && value.length && value.splice); },

			isNumber: function(value) { return typeof (value) == "number"; },

			isUndefined: function(value) { return typeof object == "undefined"; },

			"namespace": function(path) {
				amp.setValue(path, {
					__type: path,
					__namespace: true
				});
			},

			"class": function(name, base, methods) {

				var mixins = new Array();
				if (amp.isArray(base)) {
					mixins = base;
					base = mixins.shift();
				}

				var klass = function() {
					this.ctor.apply(this, arguments);
				}

				if (!klass.prototype)
					klass.prototype = {}

				klass.superclass = base;
				klass.subclasses = [];

				if (mixins.length > 0) {
					for (var i = 0; i < mixins.length; i++)
						amp.extend(klass.superclass, mixins[i]);
				}

				if (base) {
					var subclass = function() { }, ancestor = klass.superclass && klass.superclass.prototype;
					subclass.prototype = base.prototype;
					klass.prototype = new subclass();
					klass.prototype.ctor = subclass.prototype.ctor;
					base.subclasses.push(klass);
				}

				var properties = (amp.isFunction(methods)) ? methods.prototype : methods;
				for (var property in properties) {
					var value = properties[property];
					if (ancestor && amp.isFunction(value) && value.argumentNames()[0] == "$super") {

						var method = value,
				ext = (function(m) {
							return function() { return ancestor[m].apply(this, arguments) };
						})(property).wrap(method);



						value = amp.extend(ext,
						{
							valueOf: function() { return methods; },
							toString: function() { return methods.toString(); }
						});
					}
					klass.prototype[property] = value;
				}



				if (klass.prototype)
					klass.prototype.constructor = klass;


				if (!klass.prototype.ctor || klass.prototype.ctor == amp.empty) {
					if (amp.isFunction(methods))
						klass.prototype.ctor = methods;
					else
						klass.prototype.ctor = amp.empty;
				}





				klass.__class = true;
				klass.__typeName = name;
				if (base != null)
					klass.__baseType = base;

				amp.setValue(name, klass);
				return klass;

			}
		});
		
		var b = Sys.Browser;
		amp.Browser = {
			Msie: b.name == "MSIE" ? b.version : false,
			Opera: b.name == "Opera" ? b.version : false,
			Mozilla: b.name == "Firefox" ? b.version : false,
			Webkit: b.name == "Safari" ? b.version : false,
			Mobile: false,
			__type: "amp.Browser",
			__namespace: true
		}

		var ua = navigator.userAgent, m;
		if (amp.Browser.Webkit) {
			if (/ Mobile\//.test(ua)) {
				amp.Browser.Mobile = "Apple"; // iPhone or iPod Touch
			} else {
				m = ua.match(/NokiaN[^\/]*/);
				if (m) {
					amp.Browser.Mobile = m[0]; // Nokia N-series, ex: NokiaN95
				}
			}
		} else if (amp.Browser.Mobile) {
			m = ua.match(/Opera Mini[^;]*/);
			if (m) {
				amp.Browser.Mobile = m[0]; // ex: Opera Mini/2.0.4509/1316
			}
		}





		//prototype functions

		if (amp.isFunction(Array.prototype.forEach))
			Array.prototype._each = Array.prototype.forEach;
		else
			Array.prototype._each = function(iterator) {
			for (var i = 0, length = this.length; i < length; i++)
				iterator(this[i]);
		}

		if (!Array.prototype._reverse) Array.prototype._reverse = Array.prototype.reverse;

		amp.extend(Array.prototype, {
			each: Array.prototype._each,

			reverse: function(inline) {
				return (inline !== false ? this : this.toArray())._reverse();
			},

			clear: function() {
				this.length = 0;
				return this;
			},

			contains: function(value) {
				for (var i = 0; i < this.length; i++)
					if (this[i] == value)
					return true;
				return false;
			},

			remove: function(items) {
				items = amp.array(items);
				return this.map(function(item) {
					if (!items.contains(item))
						return item;
				});
			},

			map: function(iterator, context) {
				iterator = iterator ? iterator.bindContext(context) : function(x) { return x };
				var results = [];
				this.each(function(value, index) {
					results.push(iterator(value, index));
				});
				return results;
			},

			invoke: function(method) {
				var args = $A(arguments).slice(1);
				if (amp.isFunction(method)) {
					return this.map(function(value) {
						return method.apply(method, $A(value).concat(args));
					});
				}
				return this.map(function(value) {
					return value[method].apply(value, args);
				});
			},

			clone: function() {
				return [].concat(this);
			}
		});

		if (amp.Browser.Webkit) {
			amp.array = function(iterable) {
				if (!iterable)
					return [];
				if (!(amp.isFunction(iterable) && iterable == '[object NodeList]') &&
		iterable.toArray)
					return iterable.toArray();

				var i = !amp.isString(iterable) ? iterable.length : 0, results = new Array(length);
				while (length--)
					results[i] = iterable[i];

				if (!results.length)
					return [iterable];

				return results;
			}
		} else {
			amp.array = function(iterable) {
				if (!iterable)
					return [];

				if (iterable.toArray)
					return iterable.toArray();

				var i = !amp.isString(iterable) ? iterable.length : 0,
					results = new Array(length);

				while (i--)
					results[i] = iterable[i];

				if (!results.length)
					return [iterable];

				return results;
			}
		}

		var $A = amp.array;

		Array.prototype.each = Array.prototype._each;


		amp.extend(Function.prototype, {
			wrap: function() {
				var __method = this;
				return function() {
					return wrapper.apply(this, [__method.bindContext(this)].concat($A(arguments)));
				}
			},

			argumentNames: function() {
				var names = this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(",");

				return names.length == 1 && !names[0] ? [] : names;
			},

			bindContext: function() {
				if (arguments.length < 2 && amp.isUndefined(arguments[0])) return this;
				var __method = this, args = $A(arguments), object = args.shift();
				return function() {
					return __method.apply(object, args.concat($A(arguments)));
				}
			},

			bindListener: function() {
				var __method = this, args = $A(arguments), object = args.shift();
				return function(event) {
					return __method.apply(object, [event || window.event].concat(args));
				}
			},

			curry: function() {
				if (!arguments.length)
					return this;

				var __method = this, args = $A(arguments);
				return function() {
					return __method.apply(this, args.concat($A(arguments)));
				}
			},

			delay: function() {
				var __method = this, args = $A(arguments), timeout = args.shift() * 1000;
				return window.setTimeout(function() {
					return __method.apply(__method, args);
				}, timeout);
			}
		});

		Function.prototype.defer = Function.prototype.delay.curry(0.01);

		amp.extend(String.prototype, {
			capitalize: function() {
				return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
			}
		});

		amp.string = function(value) {
			return (value == null) ? "" : String(value);
		}

		RegExp.prototype.match = RegExp.prototype.test;
})()

